package com.jingan.nursinghome.regulatory.dialog;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.Button;

import com.jingan.nursinghome.regulatory.R;
import com.jingan.nursinghome.regulatory.view.ClearView;
import com.jingan.nursinghome.regulatory.view.MyActionBar;
import com.jingan.nursinghome.regulatory.view.QianmiView;

import cn.android.support.v7.lib.sin.crown.base.BaseActivity;
import cn.android.support.v7.lib.sin.crown.base.BaseApplication;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/20.
 */

public class QianmiDialog extends BaseDialog {

    private QianmiDialog(BaseActivity baseActivity) {
        init(baseActivity, R.layout.dialog_qiangmi, false, false);
        window.setWindowAnimations(cn.android.support.v7.lib.sin.crown.R.style.Crown_Window_right);
        initUI();
        adapterUI();
    }

    static QianmiDialog qianmiDialog;
    MyActionBar myActionBar;

    static BaseListenner<Bitmap> mBitmapBaseListenner;

    public static QianmiDialog getInstance(BaseActivity baseActivity, BaseListenner<Bitmap> bitmapBaseListenner) {
        mBitmapBaseListenner = bitmapBaseListenner;
        if (isFinishing(qianmiDialog)) {
            qianmiDialog = new QianmiDialog(baseActivity);
        }
        return qianmiDialog;
    }

    Button btn_qianmi;
    QianmiView qianmi;
    ClearView clearView;

    void initUI() {

        myActionBar = (MyActionBar) findViewById(R.id.MyActionBar);
        myActionBar.setLeftBimapAndTitle(null, "手写签名板");
        myActionBar.setBaseListennerLeft(new BaseListenner() {
            @Override
            public void onResult(Object result) {
                dismiss();
            }
        });

        clearView = (ClearView) findViewById(R.id.clear);
        clearView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qianmi.clear();
            }
        });

        btn_qianmi = (Button) findViewById(R.id.btn_qianmi);
        btn_qianmi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //签名完成
                if (mBitmapBaseListenner != null) {
                    mBitmapBaseListenner.onResult(BaseApplication.getInstance().snapShotView(qianmi));
                }
                dismiss();
            }
        });
        qianmi = (QianmiView) findViewById(R.id.qianmi);
    }

    //清除画板
    public static void clear() {
        if (qianmiDialog != null) {
            qianmiDialog.qianmi.clear();
        }
    }

    void adapterUI() {
        ProportionUtils.getInstance().adapterScreen(baseActivity, findViewById(R.id.dialog_login_constraintLayout));
        ProportionUtils.getInstance().adapterButton(btn_qianmi);
    }

    @Override
    protected void listener() {

    }

    @Override
    protected void recycleView() {

    }
}
